package com.qiangesoft.im.controller;

import com.qiangesoft.im.pojo.dto.ImFriendDTO;
import com.qiangesoft.im.pojo.vo.ImFriendVO;
import com.qiangesoft.im.pojo.vo.ResultInfo;
import com.qiangesoft.im.service.IImFriendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 好友 前端控制器
 * </p>
 *
 * @author qiangesoft
 * @date 2024-02-07
 */
@Api(tags = "好友")
@RequiredArgsConstructor
@RestController
@RequestMapping("/im/friend")
public class ImFriendController {

    private final IImFriendService friendService;

    @PostMapping
    @ApiOperation(value = "添加好友")
    public ResultInfo<Void> addFriend(@RequestBody ImFriendDTO friendDTO) {
        friendService.addFriend(friendDTO);
        return ResultInfo.ok();
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除好友")
    public ResultInfo<Void> removeFriend(@PathVariable Long id) {
        friendService.removeFriend(id);
        return ResultInfo.ok();
    }

    @PutMapping("/{id}")
    @ApiOperation(value = "编辑好友")
    public ResultInfo<Void> updateFriend(@PathVariable Long id, @RequestBody ImFriendDTO friendDTO) {
        friendService.updateFriend(id, friendDTO);
        return ResultInfo.ok();
    }

    @GetMapping
    @ApiOperation(value = "好友列表")
    public ResultInfo<List<ImFriendVO>> listFriend(String keyword) {
        return ResultInfo.ok(friendService.listFriend(keyword));
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "好友详情")
    public ResultInfo<ImFriendVO> getFriendInfo(@PathVariable Long id) {
        return ResultInfo.ok(friendService.getFriendInfo(id));
    }

}

